//generate password
$('.generate-password').click(function(){
	$('input[name=password]').val($.generateRandomPassword(8))
	$('#password').validationEngine('hide');
});

//team name drowpdown
// $('.team_name').change(function(){
	// if($(this).val())
	// {
		// showLoader('#main');
		// var action = root + 'positions/viewitembygroupid';
		// var dt = {item: $(this).val()};		

		// $.ajax({
		   // type: 'POST',
		   // url: action,
		   // data: dt,
		   // dataType: 'json',
		   // success: function(data){
				// hideLoader();
				// $('#position_id').html('').append('<option value="0" selected="selected">- Select -</option>');
				// $.each( data, function(i, n){
					// $('#position_id').append('<option value="'+n.position_id+'">'+n.position_name+'</option>');
				// });
			// },
		   // error: function () { onError(); hideLoader(); }
		 // });
	// }
// });

//listflex
$('.listFlex').flexigrid
(
	{
		autoload: true,
		height: $('#main').height(),
		title: 'Employee List',
		url: root + module + '/listview',
		blockOpacity: 0,
		dataType: 'json',
		colModel : [
			{display: '', name : 'a.id', width : 40, align:'center', process: viewItem}
			,{display: 'Employee No.', name : 'a.employee_no', width : 66, align : 'left', sortable:true}
			,{display: 'Employee Name', name : 'a.fullname', width : 160, align : 'left', sortable:true}
			,{display: 'Username', name : 'a.username', width : 100, align : 'left', sortable:true}
			,{display: 'Email', name : 'a.email', width : 150, align : 'left', sortable:true}
			,{display: 'Position', name : 'b.position_name', width : 80, align : 'left', sortable:true}
			],
		buttons : [
			{name: 'Add', bclass: 'add', onpress : addItem},
			//{separator: true},
			{name: 'Delete', bclass: 'delete', onpress : deleteItem},
			//{separator: true}
		],
		// searchitems : [
			// {display: 'Employee No.', name : 'a.employee_no'}
			// ,{display: 'First Name', name : 'a.firstname'}
			// ,{display: 'Last Name', name : 'a.lastname'}
		// ],
		newp: 1,
		sortname: "a.fullname",
		sortorder: "asc",
		rp: 40,
		usepager: true,
		useRp: true,
		resizable: true,
		showTableToggleBtn: true,
		singleSelect: false
	}
);



//set upload
if($('#home_upload').length)
{
	var uploader = new qq.FileUploader({
			element: document.getElementById('home_upload'),
			listElement: document.getElementById('status_content'),
			upload_text: '&nbsp;',			
			// path to server-side upload script
			action: root + module + '/upload',
			// validation    
			// ex. ['jpg', 'jpeg', 'png', 'gif'] or []
			allowedExtensions: ['jpg', 'jpeg', 'png', 'gif'],        
			// each file size limit in bytes
			// this option isn't supported in all browsers
			//sizeLimit: (5000 * 1024), // max size   
			minSizeLimit: 0, // min size
			multiple: false,
			onSubmit:function(id, fileName){


			},
			onComplete: function(id, fileName, responseJSON){
				//$('input[id=uploaded-image]').val(responseJSON['filename']);
				$('#image_id').attr('src',root+'../temp/'+responseJSON['filename']);
				//alert(responseJSON['image']['image_data']);
				$('input[name=image_name]').val(responseJSON['image']['image_name']);
				$('input[name=image_size]').val(responseJSON['image']['image_size']);
				$('input[name=image_data]').val(responseJSON['image']['image_data']);
			},
	});
}